#include <libavformat/avformat.h>

int main(int argc, char const *argv[])
{
    int ret;
    // AVIOContext *server_ctx = NULL;
    // AVDictionary *opts = NULL;
    // av_dict_set(&opts, "listen", "2", 0);

    // ret = avio_open2(&server_ctx, "rtmp://0.0.0.0:1936/stream/live", AVIO_FLAG_WRITE, NULL, &opts);
    // if (ret < 0)
    // {
    //     av_log(server_ctx, AV_LOG_ERROR, "av open error %d\n", ret);
    //}

    AVDictionary *out_opts = NULL;
    av_dict_set(&out_opts, "listen", "2", 0);
    // AVIOContext *avio_out_server_ctx;
    // avio_open2(&avio_out_server_ctx, "rtmp://0.0.0.0:1936/stream/live", AVIO_FLAG_WRITE, NULL, &out_opts);

    AVFormatContext *out_server_ctx = NULL;
    avformat_alloc_output_context2(&out_server_ctx, NULL, "flv", "rtmp://0.0.0.0:1936/stream");
    
    ret = avio_open2(&out_server_ctx->pb, "rtmp://0.0.0.0:1936/stream", AVIO_FLAG_WRITE, NULL, &out_opts);
    if (ret < 0)
    {
        av_log(out_server_ctx, AV_LOG_ERROR, "open output stream error");
        return 0;
    }

    return 0;
}
